import request from "@/utils/request";
import httpRequest from "@/utils/requestUtil";
import type { UploadUserFile } from "element-plus";
import { Attachment } from "@/api/common/common";
const HOUSE_BASE_URL = "/business/house";

const HoustAPI = {
  /** 获取客户分页数据 */
  getPage(queryParams?: HousePageQuery) {
    return httpRequest.get<PageResult<HousePageVO[]>>(`${HOUSE_BASE_URL}/loadPage`, queryParams);
  },

  /**
   * 获取客户表单数据
   *
   * @param id 客户ID
   * @returns 客户表单数据
   */
  getFormData(id: string) {
    return request<any, HouseForm>({
      url: `${HOUSE_BASE_URL}/load/${id}`,
      method: "get",
    });
  },

  /** 添加客户 */
  create(data: HouseForm) {
    return httpRequest.postFileForm<PageResult<HousePageVO[]>>(`${HOUSE_BASE_URL}/add`, data);
  },

  /**
   * 更新客户
   *
   * @param data 客户表单数据
   */
  update(data: HouseForm) {
    return httpRequest.postFileForm<PageResult<HousePageVO[]>>(`${HOUSE_BASE_URL}/update`, data);
  },

  /**
   * 批量删除客户，多个以英文逗号(,)分割
   *
   * @param ids 客户ID字符串，多个以英文逗号(,)分割
   */
  deleteByIds(ids: string) {
    return request({
      url: `${HOUSE_BASE_URL}/batchDelete?ids=${ids}`,
      method: "get",
    });
  },
  
  /**
   * 根据客户id加载
   *
   * @param customerId
   */
  loadByCustomerId(customerId: string) {
    return request<any, HousePageVO[]>({
      url: `${HOUSE_BASE_URL}/loadByCustomerId?customerId=${customerId}`,
      method: "get",
    });
  },
};

export default HoustAPI;

/** 客户分页查询参数 */
export interface HousePageQuery extends PageQuery {
  /** 搜索关键字 */
  keywords?: string;

  customerId?: string;
}

/** 客户分页对象 */
export interface HousePageVO {
  /** 客户ID */
  id: string;
  /** 楼盘名称 */
  buildName?: string;
  /** 楼盘地址 */
  buildAddress?: string;
  /** 物业电话 */
  realEstatePhone?: string;
  /** 楼盘年代 */
  buildYear?: string;
  /** 房屋地址*/
  houseAddress?: string;
  /**业主名称 */
  houseOwnerName?: string;
  /**业主电话 */
  houseOwnerPhone?: string;
  /**备注 */
  remark: string;
}

/** 客户表单对象 */
export interface HouseForm {
  /** 客户ID */
  id?: string;
  /** 楼盘名称 */
  buildName?: string;
  /** 楼盘地址 */
  buildAddress?: string;
  /** 物业电话 */
  realEstatePhone?: string;
  /** 楼盘年代 */
  buildYear?: string;
  /** 房屋地址*/
  houseAddress?: string;
  /**业主名称 */
  houseOwnerName?: string;
  /**业主电话 */
  houseOwnerPhone?: string;
  /**备注 */
  remark?: string;
  files?: UploadUserFile[];
  attachments?: Attachment[];
  keepIds?: number[];
  customerId?: string;
}
